﻿using Model;
using Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class Site : System.Web.UI.MasterPage
    {
        public string uname = string.Empty;
        public bool IsLogin = false;
        public List<tb_menu> list = new List<tb_menu>();
        public string uno = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Getuno();
                GetMenu();
                if (!string.IsNullOrEmpty(Common.UICookie.ReadCookie("ClientUId")))
                {
                    int cid = Convert.ToInt32(Common.UICookie.ReadCookie("ClientUId"));
                    if (cid > 0)
                    {
                        var umodel = Common.SqlExption.GetList<Model.tb_user>().FirstOrDefault(c => c.Id.Equals(cid));
                        if (umodel != null)
                        {
                            uname = umodel.name;
                            IsLogin = true;
                        }
                    }
                }
            }
            
        }

        public void GetMenu()
        {
            list = Common.SqlExption.GetList<Model.tb_menu>().ToList();
        }

        public void Getuno() {
            var model = Common.SqlExption.GetList<Model.tb_user>().OrderByDescending(c => c.Id).FirstOrDefault();
            if (model!=null)
            {
                int ono = Convert.ToInt32(model.user_number);
                uno = (ono + 1).ToString();
            }
            else
            {
                uno = "10001";
            }

        }
    }
}